<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var status = 1;
        let userlogin = (resolve, reject) => {
            setTimeout(() => {
                if (status == 1) {
                    resolve({
                        data: '登录成功',
                        msg: 'bbbbb',
                        token: 'xyz123'
                    })
                } else {
                    reject('用户登录失败1')
                }
            }, 2000);
        };

        let getUserInfo = (resolve, reject) => {
            setTimeout(() => {
                if (status == 1) {
                    resolve({
                        data: '获取用户信息成功',
                        msg: 'dddddd'
                    })
                } else {
                    reject('用户登录失败2')
                }
            }, 1000);
        }

        // 用户先登录成功，然后用户信息成功

        new Promise(userlogin).then(res => {
            console.log(res.token);
            return new Promise(getUserInfo)
        }).then(res => {
            console.log(res);
        })
    </script>
</body>

</html>